<%@page import="com.google.gdata.data.youtube.YouTubeMediaGroup"%>
<%@page import="com.google.gdata.data.youtube.PlaylistEntry"%>
<%@page import="com.google.gdata.data.youtube.PlaylistFeed"%>
<%@page import="com.google.gdata.data.youtube.PlaylistLinkEntry"%>
<%@page import="com.google.gdata.data.youtube.PlaylistLinkFeed"%>
<%@page import="com.google.gdata.client.youtube.*"%>
<%@page import="com.mathslogica.*"%>
<%@page import="java.net.URL"%>
<%@page import="com.google.gdata.util.AuthenticationException"%>
<%@page import="com.google.gdata.util.ServiceException"%>

<table class="playlist-table" cellspacing="0" cellpadding="0">
	<tr>
		<td style="width: 200px; vertical-align: top">
			<%
				YouTubeService service = new YouTubeService(MLConstants.CLIENT_ID,
						MLConstants.APP_KEY);
				String feedUrl = MLConstants.PLAYLIST_LINK_FEED;

				try {
					/* service.setUserCredentials("moazzam.cricket@gmail.com", "indiaisthebest12!@"); */

					/* get playlist feed */
					PlaylistLinkFeed feed = service.getFeed(new URL(feedUrl),
							PlaylistLinkFeed.class);
			%>
			<ul role="navigation" id="playlist-navigation">
				<%
					/* for every playlist entry */
						for (PlaylistLinkEntry entry : feed.getEntries()) {
							String playlistID = ML.getParam(entry.getHtmlLink()
									.getHref(), MLConstants.PLAYLIST_ID);
				%>
				<li><a
					href="/playlist?<%=MLConstants.PLAYLIST_ID + "=" + playlistID%>"><%=entry.getTitle().getPlainText()%>
				</a></li>
				<%
					}
				%>
			</ul> <%
 	} catch (AuthenticationException e) {
 		// TODO Auto-generated catch block
 		e.printStackTrace();
 	} catch (ServiceException e) {
 		// TODO Auto-generated catch block
 		e.printStackTrace();
 	}
 %>

		</td>

		<td style="width: 800px; vertical-align: top"><div>
				<%
					String playlistID = request.getParameter(MLConstants.PLAYLIST_ID);

					if (playlistID != null) {
						String playlistUrl = MLConstants.PLAYLIST_ENTRY_PREFIX + "/"
								+ playlistID;
						PlaylistFeed playlistFeed = service.getFeed(
								new URL(playlistUrl), PlaylistFeed.class);
						int count = 0;
						for (PlaylistEntry playlistEntry : playlistFeed.getEntries()) {
							YouTubeMediaGroup mediaGroup = playlistEntry
									.getMediaGroup();
							String videoID = mediaGroup.getVideoId();
				%>
				<div class="image-wrapper">
					<img
						src="<%=playlistEntry.getMediaGroup().getThumbnails()
							.get(0).getUrl()%>" />
				</div>
				<div>
					<a
						href="/lesson?<%=MLConstants.PLAYLIST_ID + "=" + playlistID + "&"
							+ MLConstants.VIDEO_ID + "=" + videoID%>"><%=playlistEntry.getTitle().getPlainText()%></a>
				</div>
				<%
					}
					}
				%>

			</div></td>
	</tr>
</table>
